import { RequestTypes } from "@/const";

function concaturl(url) {
  return window.RPConfig.mgt.concat(`/application/${url}`);
}
function localUrl(url) {
  return `apis/mdm/${url}`;
}

// 获取applist
export function getAppList({ responseProcess, param }) {
  $http.post(concaturl("findApplicationPage"), param).then(res => {
    responseProcess(res.data);
  });
}
// 根据租户CODE查询租户下的应用列表
export function getAppListByTenantCode({ responseProcess, param }) {
  $http.post(concaturl("getTenantApplicationByTenantCode"), param).then(({ data }) => {
    responseProcess(data);
  });
}

export function searchAppList(param) {
  return $http.post(concaturl("findApplicationPage"), param);
}
// 根据租户查询是否为自建应用
export function getOwnedApplicationByTenantCode(param) {
  return $http.post(concaturl(`getOwnedApplicationByTenantCode?tenantCode=${param.tenantCode}&isOwned=${param.isOwned}`), param);
}

// 根据租户CODE查询租户下的应用列表
export function searchAppListByTenantCode(param) {
  return $http.post(concaturl("getTenantApplicationByTenantCode"), param);
}

// 获取表格所有所属租户（所属租户选择器列表）
export const getTenantList = () => $http.post(concaturl("findApplicationTenantList"));

// 删除应用中的一项
export const deletApp = id => $http.post(concaturl(`delete?id=${id}`));

// 根据应用id获取
export const getAppById = id => $http.get(concaturl(`getApplication?id=${id}`));

// getApplicationByCliendId
export const getApplicationByCliendId = param => $http.post(concaturl("getApplicationByCliendId"), param);

// save or update
export const saveOrUpdateApp = param => $http.post(concaturl(param.id ? "update" : "add"), param);

// find tenant page
export const findTenantPage = param =>
  $http.post(window.RPConfig.mgt.concat(`/tenant/findTenantPage`), param, null, { cache: true });

// 根据租户编码获取租户信息
export const GetTenantByCode = tenantCode =>
  $http.get(window.RPConfig.mgt.concat(`/tenant/getTenantByCode?tenantCode=${tenantCode}`));

// getApplicationByProductCode
export const getApplicationByProductCode = code =>
  $http.get(concaturl("getApplicationByProductCode?productCode=" + code));

// getApplicationByProductCodeAndTenantCode
export const getApplicationByProductCodeAndTenantCode = params => {
  params.requestType = RequestTypes.Query;
  return $http.post(concaturl("listByTenantAndProduct"), params, null, { cache: true });
};

// 当前角色  获取为当前角色分配的全部应用
export const getApplicationOfRoleAssigned = params => {
  return $http.get(concaturl(`getApplicationOfRoleAssigned?applicationCode=${params.applicationCode}`));
};
// 查询主数据组织数据开关值：
export const getMainDataStatus = params => {
  // return $http.get(localUrl(`setting/synch/status/${params.tenantCode}/${params.applicationCode}`)).then(response => response.data);
  // WYTODO:sit环境用下面的接口调用替换上面的
  return $http.get(localUrl(`data/synch/status/${params.tenantCode}/${params.applicationCode}`)).then(response => response.data);
}
// 开启主数据同步：
export const openMainDataStatus = params => {
  // return $http.post(localUrl(`setting/synch/open`),params).then(response => response.data);
  // WYTODO:sit环境用下面的接口调用替换上面的
  return $http.post(localUrl(`data/synch/open`),params).then(response => response.data);
}
// 关闭主数据同步：
export const closeMainDataStatus = params => {
  // return $http.get(localUrl(`setting/synch/close/${params.tenantCode}/${params.applicationCode}`)).then(response => response.data);
  // WYTODO:sit环境用下面的接口调用替换上面的
  return $http.get(localUrl(`data/synch/close/${params.tenantCode}/${params.applicationCode}`)).then(response => response.data);
}
// 新增应用
export const applicationAdd = params => {
  return $http.post(concaturl(`base/add`),params).then(response => response.data);
}

// 更新应用
export const applicationUpdate = params => {
  return $http.post(concaturl(`base/update`),params).then(response => response.data);
}

// 更新应用配置信息
export const applicationConfigUpdate = params => {
  return $http.post(concaturl(`config/update`),params).then(response => response.data);
}

// 检查认证配置信息
export const applicationConfigCheck = params => {
  return $http.post(concaturl(`config/check`),params).then(response => response.data);
}

// 查询应用配置信息
export const applicationConfigQuery = params => {
  return $http.post(concaturl(`config/query?applicationCode=${params.applicationCode}&tenantCode=${params.tenantCode}`),params).then(response => response.data);
}

// 查询应用配置模板
export const applicationLoadTemplate = params => {
  return $http.get(concaturl(`load/templet`),params).then(response => response.data);
}

// 获取数据类型

export const getSyncType = params => {
  return $http.get(concaturl(`sync/type`),params).then(response => response.data);
}

// 添加应用配置
export const addAppConfig = params => {
  return $http.post(concaturl(`addAppSetting`),params).then(response => response.data);
}

// 修改应用配置
export const updateAppConfig = params => {
  return $http.post(concaturl(`updateAppSetting`),params).then(response => response.data);
}

// 根据id查询应用配置
export const getAppConfigById = params => {
  return $http.post(concaturl(`getAppSettingById?id=${params.id}`),params).then(response => response.data);
}

// 根据类型查询对应的应用配置
export const getAppConfigByType = params => {
  return $http.post(concaturl(`getAppSettingByType`),params,null, {params: params}).then(response => response.data);
}
